/**
 * 国际化插件
 * @author Your Name
 * @date 2024-03-21
 */

// 这里使用临时的翻译映射，实际开发中应当使用vue-i18n等国际化插件
const translations = {
  "zh-CN": {
    menus: {
      hsAttendance: "考勤管理",
      hsProject: "项目管理",
      hsSupplier: "供应商管理",
      hsOrder: "订单管理",
      hsPersonnel: "人员管理",
      hsAttendanceRecord: "考勤记录",
      hsAttendanceRule: "考勤规则",
      hsLeave: "请假管理",
      hsOvertime: "加班管理",
      hsHoliday: "节假日管理",
      hsSettlement: "结算管理",
      // 子页面标题
      hsAddOrder: "新增订单",
      hsEditOrder: "编辑订单",
      hsOrderDetail: "订单详情",
      hsAttendanceCalendar: "考勤日历视图",
      hsAddSettlement: "新增结算单",
      hsEditSettlement: "编辑结算单",
      hsSettlementDetail: "结算单详情"
    }
  }
};

// 当前语言
const currentLocale = "zh-CN";

/**
 * 翻译函数
 * @param key 翻译键值
 * @returns 翻译后的文本
 */
export function $t(key: string): string {
  const keys = key.split(".");
  let result: any = translations[currentLocale];

  for (const k of keys) {
    if (result && result[k]) {
      result = result[k];
    } else {
      // 如果找不到翻译，则返回原键值
      return key;
    }
  }

  return result as string;
}

export default {
  install: app => {
    app.config.globalProperties.$t = $t;
  }
};
